[Frontend] vcix: lower fused matmul whose operand is vector_store'd, fix exp chunking#265
Closed
YWHyuk wants to merge 1 commit into
Closed
[Frontend] vcix: lower fused matmul whose operand is vector_store'd, fix exp chunking#265YWHyuk wants to merge 1 commit into
YWHyuk wants to merge 1 commit into
Conversation
…fix exp chunk Two fixes to the C++->Python vcix port (lower_to_vcix.py) that SDPA exercises but the gemm/bmm/conv tests do not: - _lower_matmul bailed with 'if ATag is None or BTag is None: return False', gating on an MVIN dma_start tag for both operands. In SDPA's fused scores.V matmul, operand B is the softmax output produced in place by affine.vector_store, not DMAed, so BTag stayed None and the matmul was left un-lowered -> wrong attention output. Mirror the C++ MatmulOpLowering: an operand is initialized by either a dma_start OR a preceding affine.vector_store into its root memref; bail only when an operand is truly uninitialized. BTag/BAsync stay None/0 and are only read under 'if BAsync:', so the B dma_wait is correctly skipped (as in C++). - _make_sf_vc_v_iv n>1 transcendental chunking called vector.ExtractStridedSliceOp(offsets, sizes, strides, vec) -- wrong arg order, missing the result type and vector operand, raising TypeError under these MLIR bindings. Pass (result=legal_ty, vector=vec, offsets, sizes, strides). Only reached by large transcendentals (n>1), e.g. SDPA softmax exp, so CI's small-tile (n==1) tests never hit it. Validated end-to-end (Spike+TOGSim allclose): SDPA 56 cases pass (was crash/wrong); matmul/bmm/conv2d regress clean. Bisected: C++ vcix passes SDPA, Python vcix did not; exp chunking and fine-grained ruled out separately. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes SDPA, which was broken on this branch by the C++->Python vcix port (
lower_to_vcix.py). Bisected decisively: C++ vcix passes SDPA, Python vcix does not; exp-chunking and dma-fine-grained were ruled out, leaving_lower_matmul.1. Fused matmul left un-lowered (the numerical bug).
_lower_matmulbailed onATag is None or BTag is None-- i.e. it required an MVINdma_starttag for both operands. In SDPA'sscores·Vmatmul, operand B is the softmax output produced in place byaffine.vector_store, not DMAed, soBTagstayedNoneand the matmul was left in the IR -> wrong attention output. The C++MatmulOpLoweringmarks an operand initialized by either adma_startor a precedingaffine.vector_storeinto its root memref; the Python port omitted that branch. Restored it (isAInit/isBInit).BTag/BAsyncstayNone/0 and are only read underif BAsync:, so the Bdma_waitis correctly skipped, matching C++.2. n>1 transcendental chunking crash.
_make_sf_vc_v_ivcalledvector.ExtractStridedSliceOp(offsets, sizes, strides, vec)-- wrong arg order, missing the result type and vector operand ->TypeErrorunder these MLIR bindings. Fixed to(result=legal_ty, vector=vec, offsets, sizes, strides). Only large transcendentals (n>1, e.g. SDPA softmax exp) reach it, so CI's small-tile (n==1) tests never hit it.Validated end-to-end (Spike+TOGSim allclose): SDPA 56 cases pass (was crash/wrong); matmul/bmm/conv2d regress clean. Pass-level: after the fix the Python vcix output is byte-identical to
mlir-opt -test-pytorchsim-to-vcixfor the SDPA kernel.🤖 Generated with Claude Code